package com.atguigu.spzx.manager.config;

import com.atguigu.spzx.manager.interceptor.LoginAuthInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class SpzxManagerWebMvcConfigurere implements WebMvcConfigurer {
    @Resource
    LoginAuthInterceptor loginAuthInterceptor;
    @Resource
    SpzxWhiteUrls spzxWhiteUrls;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginAuthInterceptor)
                //注册拦截器 拦截所有请求
                .addPathPatterns("/**")
                .excludePathPatterns(spzxWhiteUrls.getUrls());
    }
    //统一跨域配置
    @Override
    public void addCorsMappings(CorsRegistry registry) {
//        WebMvcConfigurer.super.addCorsMappings(registry);
        registry.addMapping("/**")
                .allowedOriginPatterns("*") //允许跨域的服务
                .allowedMethods("*")
                .allowCredentials(true) //运行携带cookie
                .allowedHeaders("*");
    }
}
